package Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.UnknownHostException;

import SecureUtil.UDPHelper;

public class UDPHelperTestServer {
	public InetAddress ip;
	public int port = 1231;
	
	public static void main(String[]args){
		UDPHelperTestServer testServer = new UDPHelperTestServer();
		
		try {
			testServer.ip = InetAddress.getLocalHost();
			InputStreamReader isr = new InputStreamReader(System.in) ;
			BufferedReader br = new BufferedReader(isr);
			DatagramSocket _clientSocket = new DatagramSocket();
			UDPHelper udphelper = new UDPHelper(_clientSocket);
			
			System.out.println(testServer.ip.toString());
			System.out.println(_clientSocket.getLocalPort());
			
			while(true){
				
				
				
				
				
				byte [] receive = udphelper.receiveBytes(0);
				String s = new String(receive);
				System.out.println(s);
				udphelper.sendBytes(receive, udphelper.fromip, udphelper.fromport);
				
			}
			
			
			
			
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
